<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Touch
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: _composeFacebook.tpl 2011-04-26 11:18:13 mirlan $
 * @author     Mirlan
 */

?>
<?php

// prevent loading if Facebook PUBLISH is disabled
if ('publish' != Engine_Api::_ ()->getApi ( 'settings', 'core' )->core_facebook_enable)
	return;

	// prevent loading if user is not logged into Facebook
$facebook = User_Model_DbTable_Facebook::getFBInstance ();
if (! $facebook->getSession ())
	return;

	// prevent loading if the user is not logged into the correct Facebook account
try {
	$facebook->api ( '/me' );
	$fb_uid = Engine_Api::_ ()->getDbtable ( 'facebook', 'user' )->fetchRow ( array ('user_id = ?' => Engine_Api::_ ()->user ()->getViewer ()->getIdentity () ) );
	if (! $fb_uid || ! $fb_uid->facebook_uid || $fb_uid->facebook_uid != $facebook->getUser ())
		throw new Exception ( 'User logged into a Facebook account other than the attached account.' );
} catch ( Exception $e ) {
	return;
}

$this->headScript ()->appendFile ( $this->baseUrl () . '/application/modules/User/externals/scripts/composer_facebook.js' );
?>

<script type="text/javascript">
  en4.core.runonce.add(function() {
    composeInstance.addPlugin(new Composer.Plugin.Facebook({
      lang : {
        'Publish this on Facebook' : '<?php
								echo $this->translate ( 'Publish this on Facebook' )?>'
      }
    }));
  });
</script>
